module sidearm.vm;

immutable c_flag = 0x01;
immutable n_flag = 0x02;
immutable z_flag = 0x04;
immutable x_flag = 0x08;
immutable v_flag = 0x10;

struct vm_mem (T)
{
	this(uint memsz, uint growby=memsz/2)
	{
		mem = new T[memsz];
		grow = growby;TD
	}
	T [] mem;
	uint grow;	// if we need more mem, how much to increase by
}

/+++ Deterministic Finite Automata State Machine
 +
 +/

struct DFAState
{
	bool accept;
	int acceptSymbolIndex;
	DFAStateEdge[] edges;

	DFAState dup() const
	{
		return DFAState(accept,acceptSymbolIndex,edges.dup);
	}

	string toString()
	{
		string edgeStr =
			reduceTo(edges,
					 (string a, DFAStateEdge b)
					 {
						 return a ~ (a==""?"":",") ~ to!string(b);
					 }
					 );
		return "%s( %s, %s, %s )".format(typeof(this).stringof,accept,acceptSymbolIndex,edges);
	}
}

struct DFAStateEdge
{
	int charSetIndex;
	int targetDFAStateIndex;

	string toString()
	{
		return "%s(%s,%s)".format(typeof(this).stringof, charSetIndex, targetDFAStateIndex);
	}
}


